<template>
  <el-dialog title="配镜单查询" :close-on-click-modal="false" :visible.sync="visible" fullscreen append-to-body center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
      <div class="text item">
        <el-form inline label-width="90px">
              <el-form-item label="配镜单号">
                <el-input></el-input>
              </el-form-item>
              <el-form-item label="所属部门">
                <el-select v-model="dataForm.deptId">
                  <el-option v-for="item in deptOption" :value="item.id" :label="item.name" :key="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="配镜时间">
                <el-col :span="11">
                  <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.date1" style="width: 100%;"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2" style="text-align: center;">至</el-col>
                <el-col :span="11">
                  <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.date2" style="width: 100%;"></el-date-picker>
                </el-col>
              </el-form-item>

              <el-form-item label-width="0">
                <el-button icon="el-icon-search" type="info" plain @click="getDataList">查询</el-button>
                <el-button icon="el-icon-delete" type="info" plain @click="clearSearchForm">清空</el-button>
              </el-form-item>

        </el-form>
      </div>
    <el-table :data="dataList" height="calc(100vh - 215px)" ref="singleTable" border v-loading="dataListLoading">
      <el-table-column type="index" width="50">
        <template slot-scope="scope">
          <el-radio v-model="dataForm.supplyId" :label="scope.row.id" style="position: relative;left: 6px;top:-2px;" @change="checkSupply(scope.row)">&nbsp;</el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="billId" label="配镜单号"></el-table-column>
      <el-table-column prop="name" label="顾客姓名"></el-table-column>
      <el-table-column prop="phone1" label="顾客电话"></el-table-column>
      <el-table-column prop="createTime" label="配镜时间"></el-table-column>
      <el-table-column prop="receivablePrice" label="应收金额"></el-table-column>
    </el-table>
    <div class="avue-crud__pagination">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        background
        layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>
  </el-dialog>
</template>

<script>
  import { getDeptInfo } from '@/api/admin/dept'
  import { fetchList } from "@/api/eims/optician/glassesinfo"
  import { getObjByBillId } from '@/api/eims/optician/glassesinfo'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          deptId: '',
          date1: '',
          date2: '',
          code: '',
          name: ''
        },
        dataList: [],
        deptOption: [],
        dataListLoading: false,
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0
      }
    },
    methods: {
      init() {
        this.visible = true
        for(let key in this.dataForm){
          this.dataForm[key] = ''
        }
        this.getDeptList()
        this.getDataList()
      },
      clearSearchForm(){
        for(let key in this.dataForm){
          this.dataForm[key] = ''
        }
      },
      getDataList() {
        let params1 = {current: this.pageIndex,size: this.pageSize}
        let params2 = this.filterParams(this.dataForm)
        fetchList(Object.assign(params1,params2)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 选择制造商
      checkSupply(val) {
        this.visible = false
        let billId = val.billId
        getObjByBillId(billId).then(response => {
          if(response.data.code == '0'){
            let list = []
            let goodsList = response.data.data.saleDetailDTOList
            let goodsOptometry = response.data.data.saleOptometry
            goodsList.forEach(item => {
              let obj = {}
              if(item.glassFlag == 'R'){
                obj = item
                obj.takeMirroTime = response.data.data.takeMirroTime
                obj.consignMethod = '1'
                obj.mirrorBall = goodsOptometry.ballGlassOd
                obj.columnMirror = goodsOptometry.postGlassOd
                obj.axialDirection = goodsOptometry.axesOd
                obj.diameter = goodsOptometry.diameterOd
                obj.curvature = goodsOptometry.curvatureOd

                list.push(obj)
              }else if(item.glassFlag == 'L'){
                obj = item
                obj.takeMirroTime = response.data.data.takeMirroTime
                obj.consignMethod = '1'
                obj.mirrorBall = goodsOptometry.ballGlassOs
                obj.columnMirror = goodsOptometry.postGlassOs
                obj.axialDirection = goodsOptometry.axesOs
                obj.diameter = goodsOptometry.diameterOs
                obj.curvature = goodsOptometry.curvatureOs
                list.push(obj)
              }
            })
            this.$emit('refreshData',list)
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      //  获取部门列表
      getDeptList(){
        getDeptInfo().then(result => {
          if(result.data.code == '0'){
            this.deptOption = result.data.data
          }else{
            this.$message.error(response.data.msg)
          }
        })
      }
    }
  }
</script>

<style>
</style>
